package com.self.match.disruptor;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;
import com.self.common.param.Order;

/**
 * @version v1.0
 * @ClassName: 发送消息
 * @Description:
 * @Author: Mac
 * @Date: 2022/8/28 18:14
 */
public class DisruptorTemplate {

    private static final EventTranslatorOneArg<OrderEvent, Order> TRANSLATOR = new EventTranslatorOneArg<OrderEvent, Order>() {
        @Override
        public void translateTo(OrderEvent orderEvent, long sequence, Order input) {
            orderEvent.setSource(input);
        }
    };

    private final RingBuffer<OrderEvent> ringBuffer;

    public DisruptorTemplate(RingBuffer<OrderEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    /**
     * @Title: 发布事件
     */
    public void start(Order input){
        ringBuffer.publishEvent(TRANSLATOR,input);
    }
}
